package com.sinosoft.controller;

import java.math.BigDecimal;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.support.MessageSourceAccessor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.sinosoft.base.BaseFormController;
import com.sinosoft.base.Constants;
import com.sinosoft.orderinfomodel.OrderInfoModel;
import com.sinosoft.orderinfomodel.OrderInfoModelManager;
import com.sinosoft.user.User;
import com.sinosoft.util.DisplayGetPage;
import com.sinosoft.util.PropertiesUtil;
import com.sinosoft.util.SystemConfigUtil;

@Controller
@RequestMapping("/orderinfomodel/orderinfomodelform.html")
public class OrderInfoModelController extends BaseFormController {

	OrderInfoModelManager omodelmgr;
	private MessageSource messageSource = null;
	
	@Autowired
	public void setOrderInfoModelManager(OrderInfoModelManager omgr)
	{
		this.omodelmgr = omgr;
	}


	/**
	 * 保存购物车
	 * @param o
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(params="method=save")
	public String saveOrderModel(OrderInfoModel o,HttpServletRequest request,HttpServletResponse response)
	{
		MessageSourceAccessor text = new MessageSourceAccessor(messageSource,
				request.getLocale());
		String username = SecurityUtils.getSubject().getPrincipal().toString();
		String isdefault = request.getParameter("isdefaulmodel");
		String op = request.getParameter("operate");
		o.setUserid(username);
		o.setCreatetime(new Date());
		OrderInfoModel ro = null;
		if(isdefault!= null && isdefault.equals("1"))//保存为默认模版
		{
			int defa = 1;
			o.setIsdefaulmodel(new BigDecimal(1));
			/**
			 * 先查询出默认模板
			 * 修改未默认模板
			 */
			ro = omodelmgr.saveOrderInfoModelExistDefaultModel(o,username, defa);
		}
		else if(isdefault!= null && isdefault.equals("3"))//系统默认模版
		{
			String productlevel = o.getProductlevel();
			String satelliteid = o.getSatelliteid();
			String sensorid = o.getSensorid();
			o.setIsdefaulmodel(new BigDecimal(3));
			List<OrderInfoModel> existorderm = omodelmgr.getOrderInfoModel(productlevel, satelliteid, sensorid);
			if(op.equals("add"))
			{
				if(existorderm!=null && existorderm.size()>0)//已存在同一产品级别，卫星，传感器的订单模板
				{
					saveError(request, text
							.getMessage("errors.existing.orderinfomodel", new Object[] {
									productlevel,satelliteid ,sensorid }));
					return "orderinfomodel/orderinfomodelform";
				}
				ro = omodelmgr.saveOrderInfoModel(o);
			}
			else
			{
				if(existorderm!=null && existorderm.size()>1)//已存在同一产品级别，卫星，传感器的订单模板
				{
					saveError(request, text
							.getMessage("errors.existing.orderinfomodel", new Object[] {
									productlevel,satelliteid ,sensorid }));
					return "orderinfomodel/orderinfomodelform";
				}
				ro = omodelmgr.updateInfoModel(o);
			}
		}
		else
		{
			o.setIsdefaulmodel(new BigDecimal(2));
			ro = omodelmgr.saveOrderInfoModel(o);
		}
 		
		String page = request.getParameter("tz");
		String pagename = DisplayGetPage.getPageName("ordermodels", request);
		String postmethod = request.getParameter("ptmeth");
		if ("".equalsIgnoreCase(page)) {
			page = "1";
		}
		if(ro!=null)
		{
			if ("select".equalsIgnoreCase(postmethod)) {
				return "redirect:/orderinfomodel/orderinfomodelform.html?method=query&operate=select&"
						+ pagename + "=" + page;
			} else {
				return "redirect:/orderinfomodel/orderinfomodelform.html?method=query&operate=list&"
						+ pagename + "=" + page;
			}
		}
		else
			return "redirect:/orderinfomodel/orderinfomodelform.html?method=add";
	}
	
	/**
	 * 用户编辑订单模版
	 * @param request
	 * @param response
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(params="method=edit")
	public String showEditOrderModel(Model model,HttpServletRequest request,HttpServletResponse response)
	{
		OrderInfoModel o = null;
		String op = request.getParameter("operate");
		String id = request.getParameter("id");
		if(op.equals("add"))
		{
			o = new OrderInfoModel();
		}
		else
		{
			if(id!=null && !"".equals(id))
			{
				o = omodelmgr.getOrderInfoModelById(id);
				String[] sensoridlist = SystemConfigUtil.getSystemValue(o.getSatelliteid(), this.getServletContext());
				model.addAttribute("sensoridlist",sensoridlist);
			}
			else
			{
				o = new OrderInfoModel();
			}
		}
		//产品级别
		String[] productlevels = PropertiesUtil.getPropertiesValue("shopcar.productlevels", request);
		Map<String,Object> productlevelsmap = getMap(productlevels);
		model.addAttribute("productlevelsmap", productlevelsmap);
		String[] satellitelist = SystemConfigUtil.getSystemValue("satellite", this.getServletContext());
		String[] attitudedatalist = SystemConfigUtil.getSystemValue("attitudedata", this.getServletContext());
		String[] heighmodelist = SystemConfigUtil.getSystemValue("heighmodelist", this.getServletContext());
		String[] demtypelist = SystemConfigUtil.getSystemValue("demtype", this.getServletContext());
		String[] orthographmethodlist = SystemConfigUtil.getSystemValue("orthographmethod", this.getServletContext());
		String[] geodeticmethodlist = SystemConfigUtil.getSystemValue("geodeticmethod", this.getServletContext());
		String[] equationorderlist = SystemConfigUtil.getSystemValue("equationorder", this.getServletContext());
		String[] pgproductformatlist = SystemConfigUtil.getSystemValue("pgproductformat", this.getServletContext());
		String[] mapprojectionlist = SystemConfigUtil.getSystemValue("mapprojection", this.getServletContext());
		String[] weightazimuthlist = SystemConfigUtil.getSystemValue("weightazimuth", this.getServletContext());
		String[] rangelookslist = SystemConfigUtil.getSystemValue("rangelookslist", this.getServletContext());
		String[] weightrangelist = SystemConfigUtil.getSystemValue("weightrange", this.getServletContext());
		String[] reconstructprocsslist = SystemConfigUtil.getSystemValue("reconstructprocss", this.getServletContext());
		String[] addwindowlist = SystemConfigUtil.getSystemValue("addwindow", this.getServletContext());
		String[] correctphaselist = SystemConfigUtil.getSystemValue("correctphaselist", this.getServletContext());
		String[] earthmodellist = SystemConfigUtil.getSystemValue("earthmodellist", this.getServletContext());
		String[] datatypelist = SystemConfigUtil.getSystemValue("datatypelist", this.getServletContext());
		String[] resamplingkernellist = SystemConfigUtil.getSystemValue("resamplingkernel", this.getServletContext());
		String[] productorientationlist = SystemConfigUtil.getSystemValue("productorientation", this.getServletContext());
		String[] producttypelist = SystemConfigUtil.getSystemValue("producttype", this.getServletContext());
		model.addAttribute("producttypelist",producttypelist);
		String[] mapzonetypelist = SystemConfigUtil.getSystemValue("mapzonetype", this.getServletContext());
		model.addAttribute("mapzonetypelist",mapzonetypelist);
		//是否去噪
		String[] denoiseslist = PropertiesUtil.getPropertiesValue("ordermodel.denoises", request);
		Map<String,Object> denoisesmap = new HashMap<String, Object>();
		denoisesmap = this.getMap(denoiseslist);
		model.addAttribute("denoisesmap",denoisesmap);
		//MTF补偿
		String[] mtftypelist = PropertiesUtil.getPropertiesValue("ordermodel.mtftypes", request);
		Map<String,Object> mtftypemap = new HashMap<String, Object>();
		mtftypemap = this.getMap(mtftypelist);
		model.addAttribute("mtftypelist",mtftypemap);
		//辐射校正方法
		String[] radiometricmethodlist = PropertiesUtil.getPropertiesValue("ordermodel.mtftypes", request);
		Map<String,Object> radiometricmethodmap = new HashMap<String, Object>();
		radiometricmethodmap = this.getMap(radiometricmethodlist);
		model.addAttribute("radiometricmethodmap",radiometricmethodmap);
		//接收站
		String[] receivestationidlist = PropertiesUtil.getPropertiesValue("ordermodel.receivestationids", request);
		Map<String,Object> receivestationidmap = new HashMap<String, Object>();
		receivestationidmap = this.getMap(receivestationidlist);
		model.addAttribute("receivestationidmap",receivestationidmap);
		//瑞利散射
		String[] rayleighcorrectionlist = SystemConfigUtil.getSystemValue("rayleighcorrections", this.getServletContext());
		model.addAttribute("rayleighcorrectionlist",rayleighcorrectionlist);
		
		String[] earthellipsoidlist = SystemConfigUtil.getSystemValue("earthellipsoid", this.getServletContext());
		model.addAttribute("earthellipsoidlist",earthellipsoidlist);
		
		
		String[] azimuthlookslist = PropertiesUtil.getPropertiesValue("shopcar.azimuthlookslist", request);
//		SystemConfigUtil.getSystemValue("azimuthlooks", this.getServletContext());
		Map<String,Object> azimuthlooksmap = new HashMap<String, Object>();
		azimuthlooksmap = this.getMap(azimuthlookslist);
		
		model.addAttribute("heighmodelist",heighmodelist);
		model.addAttribute("azimuthlookslist",azimuthlooksmap);
		model.addAttribute("satellitelist",satellitelist);
		
		model.addAttribute("attitudedatalist",attitudedatalist);
		model.addAttribute("demtypelist",demtypelist);
		model.addAttribute("orthographmethodlist",orthographmethodlist);
		model.addAttribute("geodeticmethodlist",geodeticmethodlist);
		model.addAttribute("equationorderlist",equationorderlist);
		model.addAttribute("pgproductformatlist",pgproductformatlist);
		model.addAttribute("mapprojectionlist",mapprojectionlist);
//		model.addAttribute("azimuthlookslist",azimuthlookslist);
		model.addAttribute("weightazimuthlist",weightazimuthlist);
		model.addAttribute("correctphaselist",correctphaselist);
		model.addAttribute("rangelookslist",rangelookslist);
		model.addAttribute("weightrangelist",weightrangelist);
		model.addAttribute("reconstructprocsslist",reconstructprocsslist);
		model.addAttribute("addwindowlist",addwindowlist);
		model.addAttribute("earthmodellist",earthmodellist);
		model.addAttribute("datatypelist",datatypelist);
		model.addAttribute("resamplingkernellist",resamplingkernellist);
		model.addAttribute("productorientationlist",productorientationlist);
		//读取资源文件内容
		//1、结算方式
		Map<String,Object> clearmap = new HashMap<String, Object>();
		String[] clearformlist = PropertiesUtil.getPropertiesValue("ordermodel.clearformvalue", request);
		clearmap = this.getMap(clearformlist);
		model.addAttribute("clearform",clearmap);
		//2、订购介质
		Map<String,Object> mediummap = new HashMap<String, Object>();
		String[] mediumlist = PropertiesUtil.getPropertiesValue("shopcar.ordermediumidlist", request);
		mediummap = this.getMap(mediumlist);
		model.addAttribute("medium",mediummap);
		//3、优先级别
		Map<String,Object> prioritymap = new HashMap<String, Object>();
		String[] prioritylist = PropertiesUtil.getPropertiesValue("shopcar.prioritylist", request);
		prioritymap = this.getMap(prioritylist);
		model.addAttribute("prioritylist",prioritymap);
		//4、坐标系
		Map<String,Object> coordtypemap = new HashMap<String, Object>();
		String[] coordtypelist = PropertiesUtil.getPropertiesValue("ordermodel.coordtypelist", request);
		coordtypemap = this.getMap(coordtypelist);
		model.addAttribute("coordtypelist",coordtypemap);
		
		//5、轨道类型
		Map<String,Object> orbittypemap = new HashMap<String, Object>();
		String[] orbittypelist = PropertiesUtil.getPropertiesValue("ordermodel.orbittypelist", request);
		orbittypemap = this.getMap(orbittypelist);
		model.addAttribute("orbittypelist",orbittypemap);
		
		//6、多普勒质心计算方法
		Map<String,Object> fdcmap = new HashMap<String, Object>();
		String[] fdclist = PropertiesUtil.getPropertiesValue("ordermodel.fdclist", request);
		fdcmap = this.getMap(fdclist);
		model.addAttribute("fdclist",fdcmap);
		//7、多普勒频率计算方法
		Map<String,Object> fdrmap = new HashMap<String, Object>();
		String[] fdrlist = PropertiesUtil.getPropertiesValue("ordermodel.fdrlist", request);
		fdrmap = this.getMap(fdrlist);
		model.addAttribute("fdrlist",fdrmap);
		//8、天线方向图数据来源 
		Map<String,Object> antenmap = new HashMap<String, Object>();
		String[] antenlist = PropertiesUtil.getPropertiesValue("ordermodel.antenlist", request);
		antenmap = this.getMap(antenlist);
		model.addAttribute("antenlist",antenmap);
		//9、任务类型
		Map<String,Object> tasktypemap = new HashMap<String, Object>();
		String[] tasktypelist = PropertiesUtil.getPropertiesValue("shopcar.ordertypelist", request);
		tasktypemap = this.getMap(tasktypelist);
		model.addAttribute("tasktypelist",tasktypemap);
		
		//10、姿态类型
		Map<String,Object> atttypemap = new HashMap<String, Object>();
		String[] atttypelist = PropertiesUtil.getPropertiesValue("ordermodel.atttypelist", request);
		atttypemap = this.getMap(atttypelist);
		model.addAttribute("atttypemap",atttypemap);
		
		//11、自适应生产方式
		String[] autoprocessinglist = SystemConfigUtil.getSystemValue("autoprocessinglist", this.getServletContext());
		model.addAttribute("autoprocessinglist", autoprocessinglist);
		
		//12、波段配准
		Map<String,Object> bandregistermap = new HashMap<String,Object>();
		String[] bandregisterlist = PropertiesUtil.getPropertiesValue("ordermodel.bandregisterlist", request);
		bandregistermap = this.getMap(bandregisterlist);
		model.addAttribute("bandregistermap", bandregistermap);
		
		//13、片间均衡
		String[] ccdbalancelist = SystemConfigUtil.getSystemValue("ccdbalancelist", this.getServletContext());
		model.addAttribute("ccdbalancelist", ccdbalancelist);
		
		//13、DEM来源
		String[] demsourcelist = SystemConfigUtil.getSystemValue("demsourcelist", this.getServletContext());
		model.addAttribute("demsourcelist", demsourcelist);
		
		//13、控制点来源
		String[] gcpsourcelist = SystemConfigUtil.getSystemValue("gcpsourcelist", this.getServletContext());
		model.addAttribute("gcpsourcelist", gcpsourcelist);
		
		//14、轨道参数
		Map<String,Object> ephemerisdatamap = new HashMap<String, Object>();
		String[] ephemerisdatalist = PropertiesUtil.getPropertiesValue("shopcar.ephemerisdatas", request);
		ephemerisdatamap = this.getMap(ephemerisdatalist);
		model.addAttribute("ephemerisdatamap",ephemerisdatamap);
		
		//14、姿态参数
		Map<String,Object> attitudedatasmap = new HashMap<String, Object>();
		String[] attitudedataslist = PropertiesUtil.getPropertiesValue("ordermodel.attitudedatas", request);
		attitudedatasmap = this.getMap(attitudedataslist);
		model.addAttribute("attitudedatasmap",attitudedatasmap);
		String page = request.getParameter("tz");
		String pagename = DisplayGetPage.getPageName("ordermodels", request);
		model.addAttribute("ptmeth", request.getParameter("ptmeth"));
		model.addAttribute("tzpage", page);
		model.addAttribute("pagename", pagename);
		model.addAttribute("ordermodel",o);
		model.addAttribute("operate",op);
		return "orderinfomodel/orderinfomodelform";
	}
	
	/**
	 * 删除订单模版
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(params="method=delete")
	public String deleteOrder(HttpServletRequest request,HttpServletResponse response)
	{
		String id = request.getParameter("id");
		OrderInfoModel oimodel = omodelmgr.getOrderInfoModelById(id);
		omodelmgr.removeOrderInfo(oimodel);
		String page = request.getParameter("tz");
		String pagename = DisplayGetPage.getPageName("ordermodels", request);
		String postmethod = request.getParameter("ptmeth");
		if ("".equalsIgnoreCase(page)) {
			page = "1";
		}
		if ("select".equalsIgnoreCase(postmethod)) {
			return "redirect:/orderinfomodel/orderinfomodelform.html?method=query&operate=select&"
					+ pagename + "=" + page;
		} else {
			return "redirect:/orderinfomodel/orderinfomodelform.html?method=query&operate=list&"
					+ pagename + "=" + page;
		}
	}
	
	/**
	 * 获取订单模版列表操作
	 * @param ID订单模版ID
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(params="method=query")
	public ModelAndView showModelList(Model model,OrderInfoModel orderinfomodel,HttpServletRequest request)
	{
		String[] satellites = SystemConfigUtil.getSystemValue("satellite", this.getServletContext());
		model.addAttribute("satelliteids",satellites);
		HttpSession session = request.getSession(true);
		String op = request.getParameter("operate");
		if(op.equals("select"))
		{
			if (!ValidateNull(orderinfomodel)) {
				if(session.getAttribute("orderinfomodel")!=null)
					orderinfomodel = (OrderInfoModel)session.getAttribute("orderinfomodel");
			} else {
				session.removeAttribute("orderinfomodel");
				session.setAttribute("orderinfomodel", orderinfomodel);
			}
			model.addAttribute("ptmeth", "select");
		}
		else
		{
			model.addAttribute("ptmeth", "list");
		}
		if(orderinfomodel.getSatelliteid()!=null && !orderinfomodel.getSatelliteid().isEmpty())
		{
			String[] sensorids = SystemConfigUtil.getSystemValue(orderinfomodel.getSatelliteid(), this.getServletContext());
			model.addAttribute("sensorids",sensorids);
		}
//		String username = orderinfomodel.getUserid();
		User user =  (User) request.getSession().getAttribute(Constants.LOCAL_USER);
		Map<Long,String> authoriymap = user.getAuthoriy();
		Collection<String> authoriys = authoriymap.values();
		int isviewallorder = 0;//是否查看所有订单
		for (String s : authoriys) {
			if(s.equals(Constants.VIEW_ALL_ORDER_MODEL))
			{
				isviewallorder = 1;
				break;
			}
		}
		if(isviewallorder!=1)
		{
			orderinfomodel.setUserid(user.getUsername());
		}
//		if(!localuser.equals("admin"))
//		{
//			username = localuser;
//		}
//		orderinfomodel.setUserid(username);
		model.addAttribute("orderinfomodel",orderinfomodel);
		String[] modelstatus = PropertiesUtil.getPropertiesValue("ordermodel.modelstatus", request);
		Map<String,Object> modelmap = this.getMap(modelstatus);
		model.addAttribute("modelmap",modelmap);
		String[] prioritylist = PropertiesUtil.getPropertiesValue("shopcar.prioritylist", request);
		Map<String,Object> prioritymap = this.getMap(prioritylist);
		model.addAttribute("prioritymap",prioritymap);
		
		List<OrderInfoModel> orderinfomodellist = null;
		String page =  DisplayGetPage.getPageParamName("ordermodels",request);//第几页
		if(page==null)
		{
			orderinfomodellist = omodelmgr.getOrderInfoModelList(orderinfomodel,0,Constants.pagesize);
		}
		else
		{
			orderinfomodellist = omodelmgr.getOrderInfoModelList(orderinfomodel,(Integer.parseInt(page)-1)*Constants.pagesize,Constants.pagesize);
		}
		//产品级别
		String[] productlevels = PropertiesUtil.getPropertiesValue("shopcar.productlevels", request);
		Map<String,Object> productlevelsmap = getMap(productlevels);
		model.addAttribute("productlevelsmap", productlevelsmap);
		
		int resultSize = omodelmgr.getOrderInfoModelCount(orderinfomodel);
		model.addAttribute("resultSize",resultSize);
		model.addAttribute("pagesize",Constants.pagesize);
		double size = resultSize;
		model.addAttribute("displayallpage", Math.ceil(size / Constants.pagesize));
		model.addAttribute("thispage", Integer.parseInt(page));
		return new ModelAndView("orderinfomodel/orderinfomodellist",Constants.ORDERMODEL_LIST,orderinfomodellist);
	}
	
	/**
	 * 查看订单模板
	 * @param model
	 * @param request
	 * @param response
	 * @param map
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(params="method=view")
	public String viewOrderModel(Model model,HttpServletRequest request,HttpServletResponse response,ModelMap map)
	{
		OrderInfoModel o = null;
		String id = request.getParameter("id");
		if(id!=null && !"".equals(id))
		{
			o = omodelmgr.getOrderInfoModelById(id);
			String[] sensoridlist = SystemConfigUtil.getSystemValue(o.getSatelliteid(), this.getServletContext());
			model.addAttribute("sensoridlist",sensoridlist);
		}
		String[] satellitelist = SystemConfigUtil.getSystemValue("satellite", this.getServletContext());
		String[] mtftypelist = SystemConfigUtil.getSystemValue("mtftype", this.getServletContext());
		String[] attitudedatalist = SystemConfigUtil.getSystemValue("attitudedata", this.getServletContext());
		String[] demtypelist = SystemConfigUtil.getSystemValue("demtype", this.getServletContext());
		String[] orthographmethodlist = SystemConfigUtil.getSystemValue("orthographmethod", this.getServletContext());
		String[] geodeticmethodlist = SystemConfigUtil.getSystemValue("geodeticmethod", this.getServletContext());
		String[] equationorderlist = SystemConfigUtil.getSystemValue("equationorder", this.getServletContext());
		String[] pgproductformatlist = SystemConfigUtil.getSystemValue("pgproductformat", this.getServletContext());
		String[] mapprojectionlist = SystemConfigUtil.getSystemValue("mapprojection", this.getServletContext());
		String[] azimuthlookslist = SystemConfigUtil.getSystemValue("azimuthlooks", this.getServletContext());
		String[] weightazimuthlist = SystemConfigUtil.getSystemValue("weightazimuth", this.getServletContext());
		String[] rangelookslist = SystemConfigUtil.getSystemValue("rangelookslist", this.getServletContext());
		String[] weightrangelist = SystemConfigUtil.getSystemValue("weightrange", this.getServletContext());
		String[] reconstructprocsslist = SystemConfigUtil.getSystemValue("reconstructprocss", this.getServletContext());
		String[] addwindowlist = SystemConfigUtil.getSystemValue("addwindow", this.getServletContext());
		String[] correctphaselist = SystemConfigUtil.getSystemValue("correctphaselist", this.getServletContext());
		String[] earthmodellist = SystemConfigUtil.getSystemValue("earthmodellist", this.getServletContext());
		String[] datatypelist = SystemConfigUtil.getSystemValue("datatypelist", this.getServletContext());
		String[] resamplingkernellist = SystemConfigUtil.getSystemValue("resamplingkernel", this.getServletContext());
		String[] productorientationlist = SystemConfigUtil.getSystemValue("productorientation", this.getServletContext());
		String[] heighmodelist = SystemConfigUtil.getSystemValue("heighmodelist", this.getServletContext());
		model.addAttribute("heighmodelist",heighmodelist);
		model.addAttribute("satellitelist",satellitelist);
		model.addAttribute("mtftypelist",mtftypelist);
		model.addAttribute("attitudedatalist",attitudedatalist);
		model.addAttribute("demtypelist",demtypelist);
		model.addAttribute("orthographmethodlist",orthographmethodlist);
		model.addAttribute("geodeticmethodlist",geodeticmethodlist);
		model.addAttribute("equationorderlist",equationorderlist);
		model.addAttribute("pgproductformatlist",pgproductformatlist);
		model.addAttribute("mapprojectionlist",mapprojectionlist);
		model.addAttribute("azimuthlookslist",azimuthlookslist);
		model.addAttribute("weightazimuthlist",weightazimuthlist);
		model.addAttribute("correctphaselist",correctphaselist);
		model.addAttribute("rangelookslist",rangelookslist);
		model.addAttribute("weightrangelist",weightrangelist);
		model.addAttribute("reconstructprocsslist",reconstructprocsslist);
		model.addAttribute("addwindowlist",addwindowlist);
		model.addAttribute("earthmodellist",earthmodellist);
		model.addAttribute("datatypelist",datatypelist);
		model.addAttribute("resamplingkernellist",resamplingkernellist);
		model.addAttribute("productorientationlist",productorientationlist);
		//读取资源文件内容
		//1、结算方式
		Map<String,Object> clearmap = new HashMap<String, Object>();
		String[] clearformlist = PropertiesUtil.getPropertiesValue("ordermodel.clearformvalue", request);
		clearmap = this.getMap(clearformlist);
		model.addAttribute("clearform",clearmap);
		//2、订购介质
		Map<String,Object> mediummap = new HashMap<String, Object>();
		String[] mediumlist = PropertiesUtil.getPropertiesValue("shopcar.ordermediumidlist", request);
		mediummap = this.getMap(mediumlist);
		model.addAttribute("medium",mediummap);
		//3、优先级别
		Map<String,Object> prioritymap = new HashMap<String, Object>();
		String[] prioritylist = PropertiesUtil.getPropertiesValue("shopcar.prioritylist", request);
		prioritymap = this.getMap(prioritylist);
		model.addAttribute("prioritylist",prioritymap);
		//4、坐标系
		Map<String,Object> coordtypemap = new HashMap<String, Object>();
		String[] coordtypelist = PropertiesUtil.getPropertiesValue("ordermodel.coordtypelist", request);
		coordtypemap = this.getMap(coordtypelist);
		model.addAttribute("coordtypelist",coordtypemap);
		//5、产品类型
		String[] producttypelist = SystemConfigUtil.getSystemValue("producttype", this.getServletContext());
		model.addAttribute("producttypelist",producttypelist);
		
		Map<String,Object> orbittypemap = new HashMap<String, Object>();
		String[] orbittypelist = PropertiesUtil.getPropertiesValue("ordermodel.orbittypelist", request);
		orbittypemap = this.getMap(orbittypelist);
		model.addAttribute("orbittypelist",orbittypemap);
		
		//6、多普勒质心计算方法
		Map<String,Object> fdcmap = new HashMap<String, Object>();
		String[] fdclist = PropertiesUtil.getPropertiesValue("ordermodel.fdclist", request);
		fdcmap = this.getMap(fdclist);
		model.addAttribute("fdclist",fdcmap);
		//7、多普勒频率计算方法
		Map<String,Object> fdrmap = new HashMap<String, Object>();
		String[] fdrlist = PropertiesUtil.getPropertiesValue("ordermodel.fdrlist", request);
		fdrmap = this.getMap(fdrlist);
		model.addAttribute("fdrlist",fdrmap);
		//8、天线方向图数据来源 
		Map<String,Object> antenmap = new HashMap<String, Object>();
		String[] antenlist = PropertiesUtil.getPropertiesValue("ordermodel.antenlist", request);
		antenmap = this.getMap(antenlist);
		model.addAttribute("antenlist",antenmap);
		//9、任务类型
		Map<String,Object> tasktypemap = new HashMap<String, Object>();
		String[] tasktypelist = PropertiesUtil.getPropertiesValue("shopcar.ordertypelist", request);
		tasktypemap = this.getMap(tasktypelist);
		model.addAttribute("tasktypelist",tasktypemap);
		//11、自适应生产方式
		String[] autoprocessinglist = SystemConfigUtil.getSystemValue("autoprocessinglist", this.getServletContext());
		model.addAttribute("autoprocessinglist", autoprocessinglist);
		
		//12、波段配准
		Map<String,Object> bandregistermap = new HashMap<String,Object>();
		String[] bandregisterlist = PropertiesUtil.getPropertiesValue("ordermodel.bandregisterlist", request);
		bandregistermap = this.getMap(bandregisterlist);
		model.addAttribute("bandregistermap", bandregistermap);
		
		//13、片间均衡
		String[] ccdbalancelist = SystemConfigUtil.getSystemValue("ccdbalancelist", this.getServletContext());
		model.addAttribute("ccdbalancelist", ccdbalancelist);
		
		//14、DEM来源
		String[] demsourcelist = SystemConfigUtil.getSystemValue("demsourcelist", this.getServletContext());
		model.addAttribute("demsourcelist", demsourcelist);
		
		//15、控制点来源
		String[] gcpsourcelist = SystemConfigUtil.getSystemValue("gcpsourcelist", this.getServletContext());
		model.addAttribute("gcpsourcelist", gcpsourcelist);
		//接收站
		String[] receivestationidlist = PropertiesUtil.getPropertiesValue("ordermodel.receivestationids", request);
		Map<String,Object> receivestationidmap = new HashMap<String, Object>();
		receivestationidmap = this.getMap(receivestationidlist);
		model.addAttribute("receivestationidmap",receivestationidmap);
		map.addAttribute("ordermodel",o);
		return "orderinfomodel/vieworderinfomodel";
	}
	
	//解析list的方法
	@SuppressWarnings("unchecked")
	public Map getMap(String[] str)
	{
		Map<String,Object> map = new HashMap<String, Object>();
		for (int i = 0; i < str.length; i++) {
			String[] obj = str[i].split("_");
			if(obj.length>1)
				map.put(obj[1], obj[0]);
			else
				map.put(obj[0], obj[0]);
		}
		return map;
	}
	
	
	//判断参数是否为空
	public boolean ValidateNull(OrderInfoModel o) {
		if (o.getOrdermodelid() != null || o.getPriority()!=null || o.getSatelliteid()!=null || o.getSensorid()!=null || o.getStarttime()!=null || o.getEndtime()!=null) {
			return true;
		} else {
			return false;
		}
	}
}
